package com.bum.rss.dao;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.handlers.BeanHandler;

import com.bum.rss.exp.om.RssEntry;

public class EntryDAO {
	QueryRunner					queryRunner;

	ResultSetHandler<RssEntry>	beanHandler	= new BeanHandler<RssEntry>(RssEntry.class);

	public void add(String site, String id, String title, String content) {
		try {
			queryRunner.update("INSERT INTO " + site + " (ID, TITLE, CONTENT) VALUES (?, ?, ?)",
					id, title, content);
		} catch (SQLException e) {
		}
	}

	public RssEntry get(String site, String id) {
		try {
			return queryRunner.query("SELECT TITLE AS title, CONTENT AS content FROM " + site + " WHERE ID=?", beanHandler, id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	public void setQueryRunner(QueryRunner queryRunner) {
		this.queryRunner = queryRunner;
	}
}
